Solving 10385 - Duathlon (Ternary search)
[andmenj-acm.git] / 11511 - Frieze Patterns / frieze.2.cpp
bloba14c79508f914cb836ff254bb3f3491dfe668537
1 /*
2 Accepted
3 */
4 #include<iostream>
5 #include<cstdio>
6 #include<vector>
7 using namespace std;
9 unsigned long long f[1005][1005];
11 int main(){
12 int n, row, col;
13 while (cin >> n >> row >> col && n){
15 for (int i=1; i<=n; ++i) cin >> f[i][1];
17 for (int j=1; j<=n+1; ++j) f[1][j] = f[n][j] = 1;
19 for (int j=2; j<=n+1; ++j)
20 for (int i=2; i<n; ++i)
21 f[i][j] = (f[i+1][j-1]*f[i-1][j]+1)/f[i][j-1];
25 for (int i=1; i<=n; ++i){
26 for (int j=1; j<=n+1; ++j)
27 printf("%3d ", f[i][j]);
28 puts("");
32 while (col > n+1) col -= n+1;
34 cout << f[row][col] << endl;
36 return 0;